# author: alex
# time: 2022/4/26 17:07
"""
    收藏测试
"""

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.common.action_chains import ActionChains

bs=webdriver.Chrome()
bs.get('http://localhost:8082/log-reg')
bs.implicitly_wait(15)


bs.maximize_window()
time.sleep(1)
# 登录
username=bs.find_element(By.CSS_SELECTOR,'#form2 > span:nth-child(2) > input')
password=bs.find_element(By.CSS_SELECTOR,'#form2 > span:nth-child(3) > input')
username.send_keys('12345678901')
password.send_keys('123456')
btn=bs.find_element(By.CSS_SELECTOR,'#form2 > button')
btn.click()
time.sleep(2)
canvas = bs.find_element(By.CSS_SELECTOR,'body > canvas:nth-child(1)')
ActionChains(bs).move_to_element(canvas).move_by_offset(-475, -200).pause(2).click().perform()

time.sleep(3)
articles=bs.find_elements(By.XPATH,'//*[@id="homePage"]/div[2]/div[@class="arcticle"]')
len= len(articles)
for i in range(0,len):
    articles=bs.find_elements(By.XPATH,'//*[@id="homePage"]/div[2]/div[@class="arcticle"]')
    articles[i].click()
    time.sleep(2)
    bs.find_element(By.CSS_SELECTOR,'#blog > div.do > ul:nth-child(1) > li:nth-child(3)').click()
    bs.find_element(By.CSS_SELECTOR,'body > div.el-overlay.is-message-box > div > div.el-message-box__btns > button.el-button.el-button--default.el-button--small.el-button--primary').click()
    time.sleep(2)
    bs.back()
    time.sleep(2)
    bs.execute_script('window.scrollBy(0,60)')

time.sleep(1)